package com.facebook.imagepipeline.animated.impl;

import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Canvas;
import android.graphics.Rect;
import com.facebook.common.internal.Preconditions;
import com.facebook.common.references.CloseableReference;
import com.facebook.imagepipeline.animated.base.AnimatedDrawableBackend;
import com.facebook.imagepipeline.animated.base.AnimatedDrawableFrameInfo;
import com.facebook.imagepipeline.animated.base.AnimatedImage;
import com.facebook.imagepipeline.animated.base.AnimatedImageFrame;
import com.facebook.imagepipeline.animated.base.AnimatedImageResult;
import com.facebook.imagepipeline.animated.util.AnimatedDrawableUtil;
import javax.annotation.concurrent.GuardedBy;

public class AnimatedDrawableBackendImpl
  implements AnimatedDrawableBackend
{
  private final AnimatedDrawableUtil mAnimatedDrawableUtil;
  private final AnimatedImage mAnimatedImage;
  private final AnimatedImageResult mAnimatedImageResult;
  private final int mDurationMs;
  private final int[] mFrameDurationsMs;
  private final AnimatedDrawableFrameInfo[] mFrameInfos;
  private final int[] mFrameTimestampsMs;
  private final Rect mRenderedBounds;

  @GuardedBy("this")
  private Bitmap mTempBitmap;

  public AnimatedDrawableBackendImpl(AnimatedDrawableUtil paramAnimatedDrawableUtil, AnimatedImageResult paramAnimatedImageResult, Rect paramRect)
  {
    this.mAnimatedDrawableUtil = paramAnimatedDrawableUtil;
    this.mAnimatedImageResult = paramAnimatedImageResult;
    this.mAnimatedImage = paramAnimatedImageResult.getImage();
    this.mFrameDurationsMs = this.mAnimatedImage.getFrameDurations();
    this.mAnimatedDrawableUtil.fixFrameDurations(this.mFrameDurationsMs);
    this.mDurationMs = this.mAnimatedDrawableUtil.getTotalDurationFromFrameDurations(this.mFrameDurationsMs);
    this.mFrameTimestampsMs = this.mAnimatedDrawableUtil.getFrameTimeStampsFromDurations(this.mFrameDurationsMs);
    this.mRenderedBounds = getBoundsToUse(this.mAnimatedImage, paramRect);
    this.mFrameInfos = new AnimatedDrawableFrameInfo[this.mAnimatedImage.getFrameCount()];
    for (int i = 0; i < this.mAnimatedImage.getFrameCount(); i++)
      this.mFrameInfos[i] = this.mAnimatedImage.getFrameInfo(i);
  }

  private static Rect getBoundsToUse(AnimatedImage paramAnimatedImage, Rect paramRect)
  {
    if (paramRect == null)
      return new Rect(0, 0, paramAnimatedImage.getWidth(), paramAnimatedImage.getHeight());
    return new Rect(0, 0, Math.min(paramRect.width(), paramAnimatedImage.getWidth()), Math.min(paramRect.height(), paramAnimatedImage.getHeight()));
  }

  private void renderImageSupportsScaling(Canvas paramCanvas, AnimatedImageFrame paramAnimatedImageFrame)
  {
    double d1 = this.mRenderedBounds.width() / this.mAnimatedImage.getWidth();
    double d2 = this.mRenderedBounds.height() / this.mAnimatedImage.getHeight();
    int i = (int)Math.round(d1 * paramAnimatedImageFrame.getWidth());
    int j = (int)Math.round(d2 * paramAnimatedImageFrame.getHeight());
    int k = (int)(d1 * paramAnimatedImageFrame.getXOffset());
    int m = (int)(d2 * paramAnimatedImageFrame.getYOffset());
    try
    {
      if (this.mTempBitmap == null)
        this.mTempBitmap = Bitmap.createBitmap(this.mRenderedBounds.width(), this.mRenderedBounds.height(), Bitmap.Config.ARGB_8888);
      this.mTempBitmap.eraseColor(0);
      paramAnimatedImageFrame.renderFrame(i, j, this.mTempBitmap);
      paramCanvas.drawBitmap(this.mTempBitmap, k, m, null);
      return;
    }
    finally
    {
    }
  }

  public void dropCaches()
  {
    try
    {
      if (this.mTempBitmap != null)
      {
        this.mTempBitmap.recycle();
        this.mTempBitmap = null;
      }
      return;
    }
    finally
    {
      localObject = finally;
      throw localObject;
    }
  }

  public AnimatedDrawableBackend forNewBounds(Rect paramRect)
  {
    if (getBoundsToUse(this.mAnimatedImage, paramRect).equals(this.mRenderedBounds))
      return this;
    return new AnimatedDrawableBackendImpl(this.mAnimatedDrawableUtil, this.mAnimatedImageResult, paramRect);
  }

  public AnimatedImageResult getAnimatedImageResult()
  {
    return this.mAnimatedImageResult;
  }

  public int getDurationMs()
  {
    return this.mDurationMs;
  }

  public int getDurationMsForFrame(int paramInt)
  {
    return this.mFrameDurationsMs[paramInt];
  }

  public int getFrameCount()
  {
    return this.mAnimatedImage.getFrameCount();
  }

  public int getFrameForPreview()
  {
    return this.mAnimatedImageResult.getFrameForPreview();
  }

  public int getFrameForTimestampMs(int paramInt)
  {
    return this.mAnimatedDrawableUtil.getFrameForTimestampMs(this.mFrameTimestampsMs, paramInt);
  }

  public AnimatedDrawableFrameInfo getFrameInfo(int paramInt)
  {
    return this.mFrameInfos[paramInt];
  }

  public int getHeight()
  {
    return this.mAnimatedImage.getHeight();
  }

  public int getLoopCount()
  {
    return this.mAnimatedImage.getLoopCount();
  }

  public int getMemoryUsage()
  {
    try
    {
      Bitmap localBitmap = this.mTempBitmap;
      int i = 0;
      if (localBitmap != null)
        i = 0 + this.mAnimatedDrawableUtil.getSizeOfBitmap(this.mTempBitmap);
      int j = this.mAnimatedImage.getSizeInBytes();
      int k = i + j;
      return k;
    }
    finally
    {
    }
  }

  public CloseableReference<Bitmap> getPreDecodedFrame(int paramInt)
  {
    return this.mAnimatedImageResult.getDecodedFrame(paramInt);
  }

  public int getRenderedHeight()
  {
    return this.mRenderedBounds.height();
  }

  public int getRenderedWidth()
  {
    return this.mRenderedBounds.width();
  }

  public int getTimestampMsForFrame(int paramInt)
  {
    Preconditions.checkElementIndex(paramInt, this.mFrameTimestampsMs.length);
    return this.mFrameTimestampsMs[paramInt];
  }

  public int getWidth()
  {
    return this.mAnimatedImage.getWidth();
  }

  public boolean hasPreDecodedFrame(int paramInt)
  {
    return this.mAnimatedImageResult.hasDecodedFrame(paramInt);
  }

  public void renderFrame(int paramInt, Canvas paramCanvas)
  {
    AnimatedImageFrame localAnimatedImageFrame = this.mAnimatedImage.getFrame(paramInt);
    try
    {
      if (this.mAnimatedImage.doesRenderSupportScaling())
        renderImageSupportsScaling(paramCanvas, localAnimatedImageFrame);
      while (true)
      {
        return;
        renderImageDoesNotSupportScaling(paramCanvas, localAnimatedImageFrame);
      }
    }
    finally
    {
      localAnimatedImageFrame.dispose();
    }
  }

  public void renderImageDoesNotSupportScaling(Canvas paramCanvas, AnimatedImageFrame paramAnimatedImageFrame)
  {
    int i = paramAnimatedImageFrame.getWidth();
    int j = paramAnimatedImageFrame.getHeight();
    int k = paramAnimatedImageFrame.getXOffset();
    int m = paramAnimatedImageFrame.getYOffset();
    try
    {
      if (this.mTempBitmap == null)
        this.mTempBitmap = Bitmap.createBitmap(this.mAnimatedImage.getWidth(), this.mAnimatedImage.getHeight(), Bitmap.Config.ARGB_8888);
      this.mTempBitmap.eraseColor(0);
      paramAnimatedImageFrame.renderFrame(i, j, this.mTempBitmap);
      float f1 = this.mRenderedBounds.width() / this.mAnimatedImage.getWidth();
      float f2 = this.mRenderedBounds.height() / this.mAnimatedImage.getHeight();
      paramCanvas.save();
      paramCanvas.scale(f1, f2);
      paramCanvas.translate(k, m);
      paramCanvas.drawBitmap(this.mTempBitmap, 0.0F, 0.0F, null);
      paramCanvas.restore();
      return;
    }
    finally
    {
    }
  }
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.facebook.imagepipeline.animated.impl.AnimatedDrawableBackendImpl
 * JD-Core Version:    0.6.2
 */